/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fsktms.request.api;

import fsktms.request.RequestParameters;
import fsktms.request.RequestRespond;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author salm
 */
public class RequestAPIGroup extends RequestAPIImpl
{
    public RequestAPIGroup(String groupAPIName)
    {
        super(groupAPIName);
    }
    
    @Override
    public RequestRespond execute(RequestParameters params)
    {
        try
        {
            String functionName = (String) params.get(RequestParameters.KEY_FUNCTION);
            Method funcCalled = this.getClass().getMethod(functionName, RequestParameters.class);
            RequestRespond result = (RequestRespond) funcCalled.invoke(this, params);
            return result;
        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            Logger.getLogger(RequestAPIGroup.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
        
    }
}
